package com.example.lenovo.localphotos_lxy;

import android.Manifest;
import android.content.Intent;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.Button;

import com.example.lenovo.localphotos_lxy.activity.LocalPhotoActivity;
import com.example.lenovo.localphotos_lxy.common.BaseActivity;
import com.example.lenovo.localphotos_lxy.utils.permission.PermissionCallback;
import com.example.lenovo.localphotos_lxy.utils.permission.Permissionhelp;
import com.joker.api.Permissions4M;

public class MainActivity extends BaseActivity implements View.OnClickListener {


    private Button mBtOpenPhotos;
    private String[] mStrPermissions;
    private int[] mIntCode;

    @Override
    protected void initView() {
        mBtOpenPhotos = obtainView(R.id.btOpenPhotos);

    }

    @Override
    protected void initData() {
        initPermission();
    }



    @Override
    public int getLayoutId() {
        return R.layout.activity_main;
    }

    @Override
    protected void setListener() {
        mBtOpenPhotos.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.btOpenPhotos:

                Permissionhelp.getPermissions(mActivity,mStrPermissions, mIntCode, new PermissionCallback() {
                    @Override
                    public void onSuccessful() {
                        Intent intent=new Intent(MainActivity.this, LocalPhotoActivity.class);
                        startActivity(intent);
                    }
                });
                break;
        }
    }

    @Override
    public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[]
            grantResults) {
        Permissions4M.onRequestPermissionsResult(mActivity, requestCode, grantResults);
        super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    }


    private void initPermission() {
        mStrPermissions = new String[3];
        mStrPermissions[0]=Manifest.permission.READ_EXTERNAL_STORAGE;
        mStrPermissions[1]=Manifest.permission.WRITE_EXTERNAL_STORAGE;
        mStrPermissions[2]=Manifest.permission.CAMERA;
        mIntCode = new int[3];
        mIntCode[0]=Permissionhelp.CODE_READ_EXTERNAL_STORAGE;
        mIntCode[1]=Permissionhelp.CODE_WRITE_EXTERNAL_STORAGE;
        mIntCode[2]=Permissionhelp.CODE_WRITE_EXTERNAL_CAMERA;

    }
}
